package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo6 {
    public static void main(String[] args) throws SQLException {
        Connection conn = DBUtil.getConnection();
        Statement  state = conn.createStatement();
        String  sql = "SELECT t.name,t.gender,c.class,c.floor " +
                      "FROM teacher t,class c " +
                      "WHERE t.id=c.teacher_id " +
                      "AND t.name='王克晶'";
        ResultSet rs = state.executeQuery(sql);
        while (rs.next()){
            String tname = rs.getString("t.name");
            String tgender = rs.getString("t.gender");
            String cName = rs.getString("c.name");
            int cFloor = rs.getInt("c.floor");
            System.out.println(tname+" "+tgender+" "+cName+" "+cFloor);
        }
        conn.close();
    }
}
